package com.example.gamelogic;
import java.util.ArrayList;
import java.util.Random;


public class Match {
	
	private Team home;
	private Team away;
	int home_score;
	int away_score;
	int result; //0 = not played yet // 1 = home win // 2 = draw // 3 = away win
	
	public Match(Team one, Team two){
		this.home = one;
		this.away = two;
		int score = 0;
		int home_score=0;
		int away_score=0;
		int result=0;
	}
	
	public Team getHome(){
		return this.home;
	}
	
	public Team getAway(){
		return this.away;
	}
	
	public int whoWin(){
		return result;
	}
	
	/**
	 * update the Team statistics
	 */
	public void updateTeam(){
		if(result == 1){
			home.Update('w', this.home_score, this.away_score);
			away.Update('l', this.away_score, this.home_score);
		}else if(result == 2){
			home.Update('d', this.home_score, this.away_score);
			away.Update('d', this.home_score, this.away_score);
		}else if(result == 3){
			home.Update('l', this.home_score, this.away_score);
			away.Update('w', this.home_score, this.away_score);
		}
	}
	
	/**
	 * Function tries to score a goal
	 */
	
	public void score(){
		
		Random hs = new Random();
		int t1 = home.getAverage_strong()+hs.nextInt(30);
		hs = new Random();
		int t2 = away.getAverage_strong()+hs.nextInt(20);
		hs = new Random();
		int s = hs.nextInt(2);
		
		if(t1>t2 && s == 1){
			home_score++;
		}else if(t1<t2 && s == 1)
			away_score++;
		
	}
	
	public void play(){
		
		for(int i=0; i<10;i++){
			score();
		}
				
		if(home_score>away_score)
			result=1;
		else if(home_score==away_score)
			result=0;
		else
			result=2;
		
		updateTeam();
		
	}
	
	



}
